﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

/*
 * Sprite class is an abstract class that all game objects which are drawn
 * on the screen will inherit. It has basic information for rendering.
 */

namespace LastStand.gameContent
{
	public class Sprite
	{
        //original spawn for boundry controls
        private Vector2 originPos;
        public Vector2 OriginPos
        {
            set { this.originPos = value; }
        }
        public Vector2 GetOriginPos
        {
            get { return  this.originPos; }
        }

		//vector2 holding the sprite's position.
		protected Vector2 position;

		public Vector2 GetPosition
		{
			get { return this.position; }
		}

		public Vector2 Position
		{
			set { this.position = value; }
		}

        public float PositionX
        {
            set { this.position.X = value; }
        }
        public float PositionY
        {
            set { this.position.Y = value; }
        }


        //scale of the objects texture
        private float scale;

        public float Scale
        {
            set { scale = value; }
        }

        public float GetScale
        {
            get { return scale; }
        }

		//texture2D used to render the sprite on the screen
		private Texture2D texture;

		public Texture2D Texture
		{
			get { return this.texture; }
			set { this.texture = value; }
		}

		//the name of the texture2d file that the gamecore will load 
		//from and assign to this class
		private string texFileName;

		public string TexFileName
		{
			get { return this.texFileName; }
			set { this.texFileName = value; }
		}

        /// <summary>
        /// Velocity is how fast the texture moves based on a
        /// horizontal swipe gesture
        /// </summary>
        protected Vector2 velocity;

        public Vector2 GetVelocity 
        { 
            get { return this.velocity; } 
        }
        public Vector2 Velocity 
        { 
            set { this.velocity = value; }
        }
        public float VelocityX
        {
            set { this.velocity.X = value; }
        }
        public float VelocityY
        {
            set { this.velocity.Y = value; }
        }

		protected Vector2 center;
		public Vector2 GetCenter
		{
			get { return new Vector2(this.Texture.Width / 2, this.Texture.Height / 2); }
		}
		//the draw method that all classes will inherit and override
        public virtual void Draw(SpriteBatch sb) { }

		//update method that classes will inherit and override
        public virtual void Update(GameTimerEventArgs elapsedTime) { }

        //is this structure created yet?
        public Boolean isConstructed = true;

        //is this sprite an enemy?
        public Boolean isEnemy;

        //a rectangle to check for touches and collision
        public Rectangle HitBounds
        {
            get
            {
                if (this.Texture != null)
                {
                    // create a rectangle based on the texture
                    Rectangle r = new Rectangle(
                        (int)(this.GetPosition.X),
                        (int)(this.GetPosition.Y),
                        (int)(texture.Width),
                        (int)(texture.Height));

                    // inflate the texture a little to give us some additional pad room
                    r.Inflate(25, 25);

                    return r;
                }
                return new Rectangle(0,0,0,0);
            }
        }

        public int GetDistance(Vector2 pos)
        {
            //finds the hypotenuse (or real distance) from the attackers position
            //returns that distance in int form
            int spriteDistnace = (int)Math.Sqrt(
                        Math.Pow((this.GetPosition.X - pos.X), 2)
                        +
                        Math.Pow((this.GetPosition.Y - pos.Y), 2));
            return spriteDistnace;
        }
	}
}
